angular.module('indexApp')
    .controller('giftCtrl', function ($scope, $state, $rootScope, $http, $stateParams) {
        var vm = this;
        $scope.state = $state;
        vm.http = $rootScope.http;
        // vm.is_verification = $stateParams.is_verification;
        console.log($stateParams.is_verification);
        if ($stateParams.is_verification == 1) {
            vm.is_verification = true
        } else {
            vm.is_verification = false
        }
        vm.choose = function () {
            bootbox.prompt({
                title: "请输入核销密码!",
                buttons: {
                    confirm: {
                        label: '确定',
                        className: 'btn-danger'
                    },
                    cancel: {
                        label: '取消',
                        className: 'btn-success'
                    }
                },
                inputType: 'password',
                callback: function (result) {
                    console.log(result);
                    if(result){
                        vm.gift(result)
                    }

                }
            });
        };
        vm.gift = function (password) {
            $http({
                method: 'post',
                url: vm.http + 'my_verification',
                data: {
                    user_id: $rootScope.id,
                    pass: password
                }
            })
                .then(function successCallback(res) {

                    if (res.data.code == 0) {
                        console.log(res.data);
                        $rootScope.alert(res.data.msg);
                        vm.is_verification = true;
                    }
                    else {
                        $rootScope.alert(res.data.msg);
                        // vm.is_verification = true;
                    }

                }, function errorCallback(res) {// 请求失败执行代码
                    $rootScope.alertError()
                });
        }
    });